package com.siwei.mes.enums;

import com.siwei.mes.common.exception.BizException;
import lombok.Getter;

import java.util.Arrays;

/**
 * @author chenmaolin
 * @version 1.0
 * @date 2022/10/29
 * @Description 唯一编号枚举
 */
@Getter
public enum GenerateCodeEnum {
    USER("YH", "用户"),
    EQUIPMENT("SB", "设备"),
    CHECK_BATCH("PJZB", "批检指标"),
    CHECK_QUICK("KJZB", "快检指标"),
    PROJECT("GC", "工程"),
    ORDER("GD", "工单"),
    EXPERIMENT("SYWT", "试验委托"),
    EXPERIMENT_SAMPLE_SMOKE("CY", "样品抽样"),
    EXPERIMENT_SAMPLE_TAKE("QY", "样品取样"),
    EXPERIMENT_DESC("XMSM", "试验项目说明"),
    MATERIALS_SPEC_CONFIG("CLGG", "试验项目说明"),
    MATERIALS("WL", "试验项目说明"),
    MIX_ORIOIRTION("PHB", "配合比"),
    MIX_ORIOIRTION_ADAPTATION("PHBSP", "配合比适配"),
    SUPPLIER_COMPANY("GYS", "供应商"),
    SUPPLIER_COMPANY_MATERIALS("GYSWL", "供应商物料"),
    EXPERIMENT_OUTER("WWT", "外委托"),
    QUALITY_CERTIFICATE("QC", "质量证明书编号"),
    OPEN_APPRAISAL("KPJD", "开盘鉴定记录编号"),
    OPEN_APPRAISAL_LEDGER("KPJDTZ", "开盘鉴定台账编号"),
    MIX_PROPORTION("PHBBH", "配合比通知单编号"),
    KLLZ_SAMPLENO("KLLZYPBH", "混凝土抗氯离子台账样品编号"),
    KLLZ_CONSIGNID("KLLZWTBH", "混凝土抗氯离子台账委托编号"),
    KLLZ_REPORTID("HNT", "混凝土抗氯离子台账报告编号"),

    TEST("test", "测试");

    private final String code;

    private final String name;

    GenerateCodeEnum(String code, String name) {
        this.code = code;
        this.name = name;
    }

    /**
     * 根据code查找枚举信息
     *
     * @param code
     * @return
     */
    public static GenerateCodeEnum getName(String code) {
        return Arrays.stream(values()).filter(e -> e.getCode().equals(code)).findFirst()
                .orElseThrow(() -> new BizException("该唯一编号枚举类型不存在"));
    }
}
